package com.yun.freemarker.controller;

import com.yun.freemarker.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.*;

@Controller
public class HelloController {

    @GetMapping("/basic")
    public String test(Model model) {


        // 1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        // 2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        student.setBirthday(new Date());
        student.setMoney(3000f);
        model.addAttribute("stu", student);

        Student student2 = new Student();
        student2.setName("王五");
        student2.setAge(30);
        student2.setBirthday(new Date());
        student2.setMoney(3006f);

        List<Student> list = new ArrayList<>();
        list.add(student);
        list.add(student2);

        model.addAttribute("stus", list);


        Map<String, Object> map = new HashMap<>();
        map.put("stu1", student);
        map.put("stu2", student2);

        model.addAttribute("stuMap", map);

        return "01-basic";
    }
}